package com.dubbo.microserviceweb.controller;

import com.dubbo.api.UserService;
import com.dubbo.api.model.UserModel;
import com.dubbo.microserviceweb.controller.viewobject.UserVO;
import org.springframework.ui.Model;
import com.dubbo.microserviceweb.error.BussinessException;
import com.dubbo.microserviceweb.error.EmBussinessError;
import com.dubbo.microserviceweb.response.CommonReturnType;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

@Controller
public class UserController extends BaseController {

    @Reference
    private UserService userService;

    @RequestMapping("/user")
    @ResponseBody
    public CommonReturnType getUser(@RequestParam("id") Integer id) throws BussinessException {
        UserModel userModel = userService.getUser(id);
        if(userModel == null){
            throw new BussinessException(EmBussinessError.USER_NOT_EXIST);
        }
        return CommonReturnType.create(userModel);
    }
}
